package com.xplay.xpocker.config;

import com.xplay.xpocker.interceptor.ClientVersionInterceptor;
import com.xplay.xpocker.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wanjie
 * @date 2021/3/22 15:23
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private UserLoginInterceptor userLoginInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600 * 3600);

    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       /* registry.addInterceptor(userLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(DictionaryUrlConst.ControllerHeader.sys + DictionaryUrlConst.UserController.login)
                .excludePathPatterns("/verification/generateCode")
                .excludePathPatterns("/verification/checkGenerateCode")
                .excludePathPatterns("/open/**")
                .excludePathPatterns(DictionaryUrlConst.ControllerHeader.sys + DictionaryUrlConst.UserController.create);*/
        registry.addInterceptor(new ClientVersionInterceptor()).addPathPatterns("/**");
    }
}
